<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>修改用户</title>
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <script src="/bootstrap/js/jquery.min.js"></script>
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <style>
        body {
            padding-top: 20px;
        }
        .panel-heading h1 {
            font-size: 24px;
            margin: 0;
        }
        .panel-footer {
            font-size: 12px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            font-weight: bold;
            width: 120px;
            display: inline-block;
        }
        input[type="text"],
        select {
            width: 300px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
            transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
        }
        input[type="text"]:focus,
        select:focus {
            outline: none;
            border-color: #66afe9;
            box-shadow: 0 0 8px #66afe9;
        }
        button[type="submit"] {
            margin-top: 10px;
        }
    </style>
    <style>
        .form-group select {
            width: 120px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="panel panel-success">
        <div class="panel-heading panel-title text-center">
            <h1>修改用户信息</h1>
            <div style="display: flex;">
                <button type="button" style="text-align: left" onclick="res()">重置密码</button>
            </div>
        </div>
        <div class="panel-body" align="center">
            <form method="post" action="/users/update" role="form">
                <input type="hidden" class="form-control" id="id" value="${user.id}" name="id">
                <div class="form-group">
                    <label for="img">头像:</label>
                    <input type="file" style="width: 300px" class="form-control" id="img" value="${user.img}" name="img"  width="50%">
                </div>
                <div class="form-group">
                    <label for="username">用户名:</label>
                    <input type="text" class="form-control" id="username" value="${user.username}" name="username" required placeholder="请输入用户名...">
                </div>
<%--                <div class="form-group">--%>
<%--                    <label for="password">密码:</label>--%>
<%--                    <input type="text" class="form-control" id="password"  name="password" required placeholder="请输入密码...">--%>
<%--                </div>--%>
                <div class="form-group">
                    <label for="phone">电话:</label>
                    <input type="text" class="form-control" id="phone" name="phone" value="${user.phone}" maxlength="11" pattern="^1[3-9]\d{9}$" required placeholder="请输入手机号...">
                </div>
                <%--                <div class="form-group">--%>
                <%--                    <label for="create_time">创建时间:</label>--%>
                <%--                    <input type="text" class="form-control" id="create_time" name="create_time" readonly value="">--%>
                <%--                </div>--%>
                <div class="form-group">
                    <label for="option1">锁定</label>
                    <input type="radio" id="option1" checked="checked" name="lockFlag" value="1">

                    <label for="option2">启用</label>
                    <input type="radio" id="option2" name="lockFlag" value="0">
                </div>
                <button type="submit" class="btn btn-primary" id="btn">修改</button>

            </form>
        </div>
        <div class="panel-footer text-right">
            百度在线考试平台
        </div>
    </div>
</div>
</body>
<script>
    var name = '';
    var phone = '';

    // var lockedCheckbox = document.getElementById("locked");
    // var lockedValue = lockedCheckbox.checked ? "0" : "1";
    $(document).ready(function (){
        var initname = document.getElementById("username");
        var initphone = document.getElementById("phone");
        name = initname.value;
        phone = initphone.value;
    })
    function res(){
        $.ajax({
            type:"post",
            data:{
                "id":${user.id}
            },
            url:"/users/res",
            success: function (code){
                var code =JSON.parse(code);
                if (code.code=="1"){
                    alert("重置成功...")
                }
            }
        })
    }


    $(function (){
        $("#username").change(function (){
            var initname = document.getElementById("username");
            var name1 = initname.value;
            // alert(name);
            // alert(name1)
            if (name===name1){
                var button = document.getElementById("btn");
                button.disabled = false;
            }else {
                    $.get("/users/validname",{username:$(this).val()},function (res){
                        if (res!='0'){
                            alert("该账号已被注册！");
                            var button = document.getElementById("btn");
                            button.disabled = true;
                        }
                    })
            }

        })
    })
    $(function (){
        $("#phone").change(function (){
            var initphone = document.getElementById("phone");
            var phone1 = initphone.value;
            if (phone===phone1){
                var button = document.getElementById("btn");
                button.disabled = false;
            }else {
                $.get("/users/verifyPhone",{phone:$(this).val()},function (res){
                    if (res!='0'){
                        alert("该手机号已被注册！");
                        var button = document.getElementById("btn");
                        button.disabled = true;
                    }
                })
            }

        })
    })
</script>
</html>
